%% vykresleni referenci
ax=[];
fig=[];
load(['./',slozky{i},'/hodnoty.mat']);
fig(1)=figure;
hold on
ax(1)=subplot(3,1,1);
plot(t,ref(1,1:length(t)),'-r');
title('dy');
xlabel('t [-]');
grid on
ax(2)=subplot(3,1,2);
plot(t,ref(2,1:length(t)),'-r');
title('dx');
xlabel('t [-]');
grid on
ax(3)=subplot(3,1,3);
plot(t,ref(4,1:length(t)),'-r');
title('dpsi');
xlabel('t [-]');
grid on

width=6;
height=3;
set(gcf,'InvertHardcopy','on');
set(gcf,'PaperUnits', 'inches');
myfiguresize = [0, 0, width, height];
ti = get(gca,'TightInset');
set(gcf,'PaperPosition', myfiguresize);
set(gcf,'PaperSize',[ti(1)+ti(3)+width, height+ti(2)+ti(4)]);

print(['./',slozka,'/rychlosti'],'-dpdf','-r300')

fig(2)=figure;
hold on
ax(4)=subplot(3,1,1);
plot(t,ref(3,1:length(t)),'-r');
title('psi');
xlabel('t [-]');
grid on
ax(5)=subplot(3,1,2);
plot(t,ref(5,1:length(t)),'-r');
title('Y');
xlabel('t [-]');
grid on
ax(6)=subplot(3,1,3);
plot(t,ref(6,1:length(t)),'-r');
title('X');
xlabel('t [-]');
grid on

width=6;
height=3;
set(gcf,'InvertHardcopy','on');
set(gcf,'PaperUnits', 'inches');
myfiguresize = [0, 0, width, height];
ti = get(gca,'TightInset');
set(gcf,'PaperPosition', myfiguresize);
set(gcf,'PaperSize',[ti(1)+ti(3)+width, height+ti(2)+ti(4)]);

print(['./',slozka,'/pozice'],'-dpdf','-r300')

fig(3)=figure;
hold on
plot(ref([6],1:length(t)),ref([5],1:length(t)),'-r');
grid on
title('XY')
legends={'ref'};

width=6;
height=3;
set(gcf,'InvertHardcopy','on');
set(gcf,'PaperUnits', 'inches');
myfiguresize = [0, 0, width, height];
ti = get(gca,'TightInset');
set(gcf,'PaperPosition', myfiguresize);
set(gcf,'PaperSize',[ti(1)+ti(3)+width, height+ti(2)+ti(4)]);

print(['./',slozka,'/XY'],'-dpdf','-r300')

barvy ={'b','k','g','c','m','y','b--','k--','g--','c--','m--','y--' };
%% vykresleni zbytku
for i=1:length(slozky)
    cisloBarvy=mod(i,length(barvy));
    load(['./',slozky{i},'/hodnoty.mat']);
    y=y+Y(:,1:length(y));
    figure(fig(1))
    subplot(3,1,1)
    hold on
    plot(t,y(1,:),cell2mat(barvy(cisloBarvy)));
    title('dy');
    xlabel('t [s]');
    ylabel('v [m/s]');
    grid on
    subplot(3,1,2)
    hold on
    plot(t,y(2,:),cell2mat(barvy(cisloBarvy)));
    title('dx');
    xlabel('t [s]');
    ylabel('v [m/s]');
    grid on
    subplot(3,1,3)
    hold on
    plot(t,y(4,:),cell2mat(barvy(cisloBarvy)));
    title('dpsi');
    xlabel('t [s]');
    ylabel('\phi [rad/s]');
    grid on
    
    width=6;
    height=3;
    set(gcf,'InvertHardcopy','on');
    set(gcf,'PaperUnits', 'inches');
    myfiguresize = [0, 0, width, height];
    ti = get(gca,'TightInset');
    set(gcf,'PaperPosition', myfiguresize);
    set(gcf,'PaperSize',[ti(1)+ti(3)+width, height+ti(2)+ti(4)]);
    
    print(['./',slozka,'/rychlosti'],'-dpdf','-r300')
    
    figure(fig(2))
    subplot(3,1,1)
    hold on
    plot(t,y(3,:),cell2mat(barvy(cisloBarvy)));
    title('psi');
    xlabel('t [s]');
    ylabel('[rad]')
    grid on
    subplot(3,1,2)
    hold on
    plot(t,y(5,:),cell2mat(barvy(cisloBarvy)));
    title('Y');
    xlabel('t [s]');
    ylabel('[m]');
    grid on
    subplot(3,1,3)
    hold on
    plot(t,y(6,:),cell2mat(barvy(cisloBarvy)));
    title('X');
    xlabel('t [s]');
    ylabel('[m]');
    grid on
    
    width=6;
    height=3;
    set(gcf,'InvertHardcopy','on');
    set(gcf,'PaperUnits', 'inches');
    myfiguresize = [0, 0, width, height];
    ti = get(gca,'TightInset');
    set(gcf,'PaperPosition', myfiguresize);
    set(gcf,'PaperSize',[ti(1)+ti(3)+width, height+ti(2)+ti(4)]);
    
    print(['./',slozka,'/pozice'],'-dpdf','-r300')
    
    figure(fig(3))
    hold on
    plot(y(6,:),y(5,:),cell2mat(barvy(cisloBarvy)))
    grid on
    title('XY')
    legends(i+1)={['case ',num2str(i)]};
    legend(legends,'Location','SouthEast');
    
    width=6;
    height=3;
    set(gcf,'InvertHardcopy','on');
    set(gcf,'PaperUnits', 'inches');
    myfiguresize = [0, 0, width, height];
    ti = get(gca,'TightInset');
    set(gcf,'PaperPosition', myfiguresize);
    set(gcf,'PaperSize',[ti(1)+ti(3)+width, height+ti(2)+ti(4)]);
    axis equal
    
    print(['./',slozka,'/XY'],'-dpdf','-r300')
end

linkaxes(ax,'x');